package io.adminboot.utils;

import com.google.gson.Gson;

public class JsonUtils {

    /**
     * Object 转成 JSON 数据
     */
    public static String toJson(Object object){
        if(object instanceof Integer || object instanceof Long || object instanceof Float ||
                object instanceof Double || object instanceof Boolean || object instanceof String){
            return String.valueOf(object);
        }
        return new Gson().toJson(object);
    }

    /**
     * JSON 数据转成 Object
     */
    public static <T> T fromJson(String json, Class<T> clazz){
        return new Gson().fromJson(json, clazz);
    }

}
